/**
 * 
 */
package net.xfok.xdict;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * @author YangHua
 *
 */
public class IndexAdapter extends BaseAdapter {
	
	private List<String> indexs;
	private LayoutInflater mInflater;
	private Context context;

	public IndexAdapter(Context context){
		mInflater = LayoutInflater.from(context);
		indexs=new ArrayList<String>();
		this.context=context;
	}

	public int getCount() {
		// TODO Auto-generated method stub
		return indexs.size();
	}

	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return indexs.get(position);
	}

	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.list_item, null);
			holder = new ViewHolder();
			holder.text = (TextView) convertView.findViewById(R.id.text);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.text.setText(indexs.get(position));
		return convertView;
    }
 	static class ViewHolder {
 		TextView text;
 	}
 	
 	public void add(String index){
 		if(indexs!=null){
 			indexs.add(index);
 		}
 	}

}
